from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-30 14:04:00.634702
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 30, Aug, 2022
Time: 14:04:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2568
Nobs: 764.000 HQIC: -50.5928
Log likelihood: 9740.20 FPE: 8.63893e-23
AIC: -50.8032 Det(Omega_mle): 7.68479e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300754 0.054758 5.492 0.000
L1.Burgenland 0.106659 0.036410 2.929 0.003
L1.Kärnten -0.106789 0.019348 -5.519 0.000
L1.Niederösterreich 0.205909 0.076096 2.706 0.007
L1.Oberösterreich 0.114335 0.073789 1.549 0.121
L1.Salzburg 0.252636 0.038970 6.483 0.000
L1.Steiermark 0.035721 0.050827 0.703 0.482
L1.Tirol 0.106804 0.041151 2.595 0.009
L1.Vorarlberg -0.060681 0.035381 -1.715 0.086
L1.Wien 0.049550 0.065586 0.755 0.450
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060302 0.113760 0.530 0.596
L1.Burgenland -0.034845 0.075642 -0.461 0.645
L1.Kärnten 0.047318 0.040196 1.177 0.239
L1.Niederösterreich -0.173432 0.158089 -1.097 0.273
L1.Oberösterreich 0.395783 0.153295 2.582 0.010
L1.Salzburg 0.289819 0.080960 3.580 0.000
L1.Steiermark 0.105243 0.105593 0.997 0.319
L1.Tirol 0.314415 0.085490 3.678 0.000
L1.Vorarlberg 0.026488 0.073504 0.360 0.719
L1.Wien -0.023804 0.136255 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190962 0.028157 6.782 0.000
L1.Burgenland 0.089467 0.018722 4.779 0.000
L1.Kärnten -0.008682 0.009949 -0.873 0.383
L1.Niederösterreich 0.259662 0.039129 6.636 0.000
L1.Oberösterreich 0.134400 0.037942 3.542 0.000
L1.Salzburg 0.045897 0.020038 2.290 0.022
L1.Steiermark 0.017464 0.026135 0.668 0.504
L1.Tirol 0.093706 0.021160 4.428 0.000
L1.Vorarlberg 0.058445 0.018193 3.212 0.001
L1.Wien 0.119747 0.033725 3.551 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108230 0.028597 3.785 0.000
L1.Burgenland 0.047477 0.019015 2.497 0.013
L1.Kärnten -0.014677 0.010104 -1.453 0.146
L1.Niederösterreich 0.192185 0.039740 4.836 0.000
L1.Oberösterreich 0.290128 0.038535 7.529 0.000
L1.Salzburg 0.111815 0.020351 5.494 0.000
L1.Steiermark 0.102186 0.026544 3.850 0.000
L1.Tirol 0.110311 0.021490 5.133 0.000
L1.Vorarlberg 0.069624 0.018477 3.768 0.000
L1.Wien -0.017992 0.034251 -0.525 0.599
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130265 0.051940 2.508 0.012
L1.Burgenland -0.051666 0.034537 -1.496 0.135
L1.Kärnten -0.040270 0.018353 -2.194 0.028
L1.Niederösterreich 0.170146 0.072180 2.357 0.018
L1.Oberösterreich 0.140586 0.069992 2.009 0.045
L1.Salzburg 0.288028 0.036965 7.792 0.000
L1.Steiermark 0.032175 0.048212 0.667 0.505
L1.Tirol 0.161881 0.039033 4.147 0.000
L1.Vorarlberg 0.100599 0.033561 2.998 0.003
L1.Wien 0.070174 0.062211 1.128 0.259
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056631 0.041362 1.369 0.171
L1.Burgenland 0.040414 0.027503 1.469 0.142
L1.Kärnten 0.050298 0.014615 3.442 0.001
L1.Niederösterreich 0.220833 0.057480 3.842 0.000
L1.Oberösterreich 0.283949 0.055737 5.094 0.000
L1.Salzburg 0.045749 0.029436 1.554 0.120
L1.Steiermark -0.001256 0.038393 -0.033 0.974
L1.Tirol 0.148002 0.031084 4.761 0.000
L1.Vorarlberg 0.072620 0.026726 2.717 0.007
L1.Wien 0.083616 0.049542 1.688 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180320 0.049529 3.641 0.000
L1.Burgenland -0.005762 0.032933 -0.175 0.861
L1.Kärnten -0.061402 0.017500 -3.509 0.000
L1.Niederösterreich -0.082546 0.068829 -1.199 0.230
L1.Oberösterreich 0.197275 0.066742 2.956 0.003
L1.Salzburg 0.056148 0.035248 1.593 0.111
L1.Steiermark 0.230576 0.045973 5.015 0.000
L1.Tirol 0.493849 0.037221 13.268 0.000
L1.Vorarlberg 0.047553 0.032002 1.486 0.137
L1.Wien -0.053792 0.059323 -0.907 0.365
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166435 0.056876 2.926 0.003
L1.Burgenland -0.010399 0.037818 -0.275 0.783
L1.Kärnten 0.067142 0.020096 3.341 0.001
L1.Niederösterreich 0.206717 0.079039 2.615 0.009
L1.Oberösterreich -0.070838 0.076642 -0.924 0.355
L1.Salzburg 0.211392 0.040477 5.223 0.000
L1.Steiermark 0.115698 0.052793 2.192 0.028
L1.Tirol 0.071747 0.042742 1.679 0.093
L1.Vorarlberg 0.121570 0.036749 3.308 0.001
L1.Wien 0.122159 0.068123 1.793 0.073
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359455 0.032843 10.945 0.000
L1.Burgenland 0.005892 0.021838 0.270 0.787
L1.Kärnten -0.023338 0.011605 -2.011 0.044
L1.Niederösterreich 0.214256 0.045641 4.694 0.000
L1.Oberösterreich 0.190453 0.044257 4.303 0.000
L1.Salzburg 0.045737 0.023373 1.957 0.050
L1.Steiermark -0.016323 0.030485 -0.535 0.592
L1.Tirol 0.106297 0.024682 4.307 0.000
L1.Vorarlberg 0.073238 0.021221 3.451 0.001
L1.Wien 0.045876 0.039337 1.166 0.244
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040163 0.148321 0.192091 0.157628 0.123982 0.112881 0.065920 0.221580
Kärnten 0.040163 1.000000 -0.004009 0.132922 0.041282 0.095663 0.430981 -0.052277 0.100406
Niederösterreich 0.148321 -0.004009 1.000000 0.337203 0.149919 0.299021 0.107545 0.182922 0.323069
Oberösterreich 0.192091 0.132922 0.337203 1.000000 0.227364 0.331153 0.172529 0.167980 0.264445
Salzburg 0.157628 0.041282 0.149919 0.227364 1.000000 0.146850 0.122543 0.147665 0.132318
Steiermark 0.123982 0.095663 0.299021 0.331153 0.146850 1.000000 0.150889 0.138191 0.078800
Tirol 0.112881 0.430981 0.107545 0.172529 0.122543 0.150889 1.000000 0.114964 0.151979
Vorarlberg 0.065920 -0.052277 0.182922 0.167980 0.147665 0.138191 0.114964 1.000000 0.006719
Wien 0.221580 0.100406 0.323069 0.264445 0.132318 0.078800 0.151979 0.006719 1.000000